package com.tfswue.jqr.controller;

import com.tfswue.jqr.entity.Book;
import com.tfswue.jqr.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/book")
@RefreshScope
public class BookController {

    @Autowired
    private BookService bookService;

    @GetMapping("/{id}")
    public Book getBookById(@PathVariable Long id) {
        return bookService.getBookById(id);
    }

    @PostMapping
    public void addBook(@RequestBody Book book) {
        bookService.addBook(book);
    }

    // nacos 读取配置
    @Value("${spring.data.redis.port}")
    private String port;
    @GetMapping("spring/data/redis/port")
    public String getPort() {
        return "端口:" + port;
    }
}
